package tq.com.tqstudent.ui.activity.mine;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;

import com.lib.common.base.BaseActivity;
import com.tencent.connect.share.QQShare;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

import org.greenrobot.eventbus.Subscribe;

import butterknife.OnClick;
import tq.com.tqstudent.Constants;
import tq.com.tqstudent.R;
import tq.com.tqstudent.utils.ShareUtil;

/**
 * @Author rames
 * @date 2019/3/5 17:14
 */
public class ShareActivity extends BaseActivity implements View.OnClickListener {

    public static void show(Activity activity) {
        Intent intent = new Intent(activity, ShareActivity.class);
        Bundle bundle = new Bundle();
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }

    @Override
    public int initLayout() {
        return R.layout.activity_share;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        setTitle("推荐 “班群” 给好友");
    }

    @Override
    public void initData() {
        findViewById(R.id.qq_iv).setOnClickListener(this);
        findViewById(R.id.pyq_iv).setOnClickListener(this);
        findViewById(R.id.wechat_iv).setOnClickListener(this);
    }

    @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.qq_iv:
                shareToQQ();
                break;

            case R.id.pyq_iv:
                Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_delete);
                ShareUtil.shareToPyq(this, Constants.WX_APP_ID, "www.qq.com", "title pyq", "content pyq", bitmap);
                break;

            case R.id.wechat_iv:
                Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_delete);
                ShareUtil.shareWeb(this, Constants.WX_APP_ID, "www.baidu.com", "title", "content", bitmap1);
                break;
        }
    }

    private void shareToQQ() {
        final Bundle params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
        //分享的标题。注：PARAM_TITLE、PARAM_IMAGE_URL、PARAM_    SUMMARY不能全为空，最少必须有一个是有值的。
        params.putString(QQShare.SHARE_TO_QQ_TITLE, "分享的标题");
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, "分享的内容");
        //这条分享消息被好友点击后的跳转URL。
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, "http://www.taobao.com");
        //分享的图片URL
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, "http://thirdqq.qlogo.cn/g?b=oidb&k=hiaTL1V9KxEdUuE7DtEvf0w&s=140");
        //手Q客户端顶部，替换“返回”按钮文字，如果为空，用返回代替
        params.putString(QQShare.SHARE_TO_QQ_APP_NAME, this.getString(R.string.app_name));
//        params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, "其他附加功能");
        Tencent mTencent = Tencent.createInstance(Constants.QQ_APP_ID, this);
        mTencent.shareToQQ(this, params, new IUiListener() {
            @Override
            public void onComplete(Object o) {
                showToast("分享成功");
                finish();
            }

            @Override
            public void onError(UiError uiError) {
                showToast("分享失败:"+uiError.errorDetail);
            }

            @Override
            public void onCancel() {

            }
        });
    }
}
